package org.example.core.valid.annontation;

import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

/**
 * @author 小杰_cc
 * @version 1.0
 */
public class TypeValueConstrainValidator implements ConstraintValidator<TypeValue, String> {
    private Set<String> set =  new HashSet<>();

    @Override
    public void initialize(TypeValue constraintAnnotation) {
        String[] value = constraintAnnotation.value();
        set.addAll(Arrays.asList(value));
    }

    @Override
    public boolean isValid(String type, ConstraintValidatorContext constraintValidatorContext) {
        return set.contains(type);
    }
}
